package com.zwps.biz.controller.http;

import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zwps.biz.api.model.dto.dept.AddDeptDTO;
import com.zwps.biz.api.model.dto.dept.SelectTreeDTO;
import com.zwps.biz.api.model.dto.dept.UpdateDeptDTO;
import com.zwps.biz.api.model.vo.dept.DeptTreeVO;
import com.zwps.biz.domain.service.DeptService;
import com.zwps.common.controller.CommonController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 系统部门
 * 
 * @ClassName: DeptController
 * @Description:
 * @author lyh
 * @date 2023年5月17日 上午10:34:27
 *
 */
@Tag(name = "部门管理")
@RestController
@RequestMapping("system/dept")
@Validated
public class DeptController extends CommonController {

    @Autowired
    private DeptService deptService;

    @Operation(summary = "新增部门")
    @PostMapping
    public void addDept(@Valid @NotNull @RequestBody AddDeptDTO dto) {
        deptService.addDept(dto);
    }

    //    @Operation(summary = "分页查询部门")
//    @GetMapping("page")
//    public ResponseDataPageMessage<DeptVO> selectDeptPage(SelectDeptDTO dto) {
//        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
//        Page<DeptDO> page = (Page<DeptDO>) deptService.selectDepts(dto);
//        return ResponseDataPageMessage.data(page, DeptConverter.INSTANCE.toDeptVOList(page.getResult()));
//    }


    @Parameter(name = "parentId", description = "上级部门ID")
    @Parameter(name = "countUserNum", description = "是否统计用户数量（1：统计）")
    @Operation(summary = "查询部门树")
    @GetMapping("tree")
    public List<DeptTreeVO> findDeptTree(SelectTreeDTO dto) {
        return deptService.findDeptTree(dto);
    }
    
    @Parameter(name = "deptId", description = "部门ID")
    @Operation(summary = "查询指定部门所有上级部门ID列表")
    @GetMapping("parent_ids")
    public List<String> findDeptParentIds(@Valid @NotBlank String deptId) {
        return deptService.findDeptParentIds(deptId);
    }

    @Operation(summary = "删除部门")
    @DeleteMapping("{ids}")
    public void deleteDepts(@Valid @NotBlank @PathVariable String ids) {
        deptService.deleteDepts(ids);
    }

    @Parameter(name = "id", description = "部门ID", in = ParameterIn.PATH)
    @Operation(summary = "修改部门信息")
    @PutMapping("{id}")
    public void updateDept(@Valid @NotBlank @PathVariable String id, @Valid @NotNull @RequestBody UpdateDeptDTO dto) {
        deptService.updateDept(id, dto);
    }
}
